import time

from xjlibrary.mprocesspoll.MThreadingRun import MThreadingRun
from xjlibrary.our_file_dir import BaseDir

"""
快速删除某个目录里的小文件
"""
# 指定该参数即可
SourceDir = r"F:\test2\test"


class articleThreadRun(MThreadingRun):

    def __init__(self, num):
        super(articleThreadRun, self).__init__(num)
        self.time_start = time.time()

    def getTask(self, *args, **kwargs):
        pass

    def setTask(self, results=None, *args, **kwargs):
        count = 0
        for filepath in BaseDir.get_dir_all_files(SourceDir):
            self.add_job(self.func, filepath)
            count += 1
            if count % 1000 == 1:
                print(count)
                time_end = time.time()
                print('totally cost', time_end - self.time_start)
        time.sleep(60)

    def dealresult(self, *args, **kwargs):
        time.sleep(60)

    def setProxy(self, proxysList=None):
        time.sleep(60)

    def thread_pool_hook(self, thread_pool_dicts, thread, args, kwargs):
        return {}

    def is_break(self):
        return True

    def fun(self, threadval, *args, **kwargs):
        filepath = args[0]
        BaseDir.remove_file(filepath)


run = articleThreadRun(50)
run.run()
